/**
 * 
 */
package name.yzhu.wordsearch;

/**
 * @author yhzhu
 *
 */
/**
 * A generic position should have two point X(first) and Y(second) .
 * And both X and Y must need to be no-negative otherwise IllegalArgumentException will be throw
 */
public class Position {
    protected int first = -1;
    protected int second = -1;

    public Position(){}
    
    public Position(Position p){
    	setFirst(p.getFirst());
    	setSecond(p.getSecond());
    }
    
	public Position(int first, int second) {
		setFirst(first);
		setSecond(second);
	}

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		if (first < 0)
			throw new IllegalArgumentException("first must need to be no-negative ("+first+")");
		this.first = first;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		if (second < 0)
			throw new IllegalArgumentException("second must need to be no-negative ("+second+")");
		this.second = second;
	}

	@Override
	public String toString() {
		return "Position [first=" + first + ", second=" + second + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + first;
		result = prime * result + second;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Position other = (Position) obj;
		if (first != other.first)
			return false;
		if (second != other.second)
			return false;
		return true;
	}
}
